package br.ufc.ck0017.ir.tree;

import br.ufc.ck0017.temp.Label;

import java.util.ArrayList;
import java.util.List;

public class CJUMP implements IRNode {
    private final Label ifTrue;
    private final Label ifFalse;
    private final IRNode leftOperand;
    private final IRNode rightOperand;
    private final LogicalOperator operator;

    public enum LogicalOperator {
        EQ,
        NE,
        LT,
        GT,
        LE,
        GE,
        ULT,
        ULE,
        UGT,
        UGE;
    }

    CJUMP(LogicalOperator operator, IRNode leftOperand, IRNode rightOperand, Label ifTrue, Label ifFalse) {
        this.operator = operator;
        this.ifTrue = ifTrue;
        this.ifFalse = ifFalse;
        this.leftOperand = leftOperand;
        this.rightOperand = rightOperand;
    }

    @Override
    public List<IRNode> getChildren() {
        List<IRNode> children = new ArrayList<>(2);
        children.add(leftOperand);
        children.add(rightOperand);

        return children;
    }

    @Override
    public IRNode build(List<IRNode> children) {
        return new CJUMP(operator, children.get(0), children.get(1), ifTrue, ifFalse);
    }
}
